package examples.complex.viewmodel.personwelcome

import de.saxsys.mvvmfx.ViewModel
import examples.complex.model.Gender
import examples.complex.model.Person
import examples.complex.model.Repository
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty

import javax.inject.Inject

/**
 * Created by Misty on 2015/6/5.
 */
class PersonWelcomeViewModel implements ViewModel {
    final Repository repository

    final StringProperty welcomeString = new SimpleStringProperty()

    private Person person

    @Inject
    public PersonWelcomeViewModel(Repository repository) {
        this.repository = repository
    }

    void setPersonId(int personId) {
        person = repository.getPersonById(personId)

        String salutation
        switch (person.gender) {
            case Gender.MALE:
                salutation = "Herr "
                break
            case Gender.FEMALE:
                salutation = "Frau "
                break
            default:
                salutation = "Herr/Frau/* "
        }
        welcomeString.set("Willkommen $salutation ${person.firstName} ${person.lastName}")
    }

    int getPersonId() {
        return person.id
    }
}
